import 'package:flutter/material.dart';

import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'package:hive_flutter/hive_flutter.dart';
import './models/task_model.dart';
import './services/task_service.dart';
import './services/notification_service.dart';
import './viewmodels/task_view_model.dart';
import './views/main_screen.dart';

void main() async {
  // 初始化Flutter
  WidgetsFlutterBinding.ensureInitialized();

  // 初始化任务服务和通知服务
  final taskService = TaskService();
  await taskService.init();
  final notificationService = NotificationService();

  // 运行应用
  runApp(MyApp(
    taskService: taskService,
    notificationService: notificationService,
  ));
}

class MyApp extends StatelessWidget {
  final TaskService taskService;
  final NotificationService notificationService;

  const MyApp({
    super.key,
    required this.taskService,
    required this.notificationService,
  });

  @override
  Widget build(BuildContext context) {
    return MultiProvider(
      providers: [
        ChangeNotifierProvider(
          create: (context) => TaskViewModel(
            taskService,
            notificationService,
          ),
        ),
      ],
      child: MaterialApp(
        title: '打卡提醒',
        theme: ThemeData(
          primarySwatch: Colors.blue,
          visualDensity: VisualDensity.adaptivePlatformDensity,
        ),
        home: const MainScreen(),
        debugShowCheckedModeBanner: false,
      ),
    );
  }
}
